package P3_Redirect;

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.IOException;

public class Response1 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println("Response1");

        request.setAttribute("key1","value1");
        // 设置响应状态码302，表示重定向
        response.setStatus(302);
        // 设置响应头，说明新的地址在哪里
        //不推荐使用此方法：
        response.setHeader("Location","http://localhost:8080/WebApp01_war_exploded/Response2");
        //推荐使用以下方法：
        response.sendRedirect("http://localhost:8080/WebApp01_war_exploded/Response2");
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
